public class Test {


    public static void main(String[] args) {
        Person[] persons = new Person[10];
        persons[0] = new Person("John", 20);
        persons[1] = new Person("Jane", 21);
        persons[2] = new Person("Jack", 22);
        persons[3] = new Person("Jill", 23);
        persons[4] = new Person("Joe", 24);
        persons[5] = new Person("Jen", 25);
        persons[6] = new Person("Judy", 26);
        persons[7] = new Person("Jerry", 27);
        persons[8] = new Person("Judy", 28);
        persons[9] = new Person("Judy", 29);
        for (Person person : persons) {
            System.out.println(person.getName() + " " + person.getAge());
        }
        // 排序
        sort(persons);
        System.out.println("----------------");
        // 输出排序后的结果
        for (Person person : persons) {
            System.out.println(person.getName() + " " + person.getAge());
        }
    }

    // 冒泡排序
    public static void sort(Person[] persons) {
        for (int i = 0; i < persons.length; i++) {
            for (int j = 0; j < persons.length; j++) {
                if (persons[i].getAge() > persons[j].getAge()) {
                    Person temp = persons[i];
                    persons[i] = persons[j];
                    persons[j] = temp;
                }
            }
        }
    }
}
